package com.androidx.p013lv.base.utils;

import android.content.Context;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/* renamed from: com.androidx.lv.base.utils.AccountCacheUtils */
public class AccountCacheUtils {
    private static String DataCache = "kbFile";
    public static String savePath = Environment.getExternalStorageDirectory().getPath();

    public static void saveCache(Context context, String str) {
        new DataCache().saveGlobal(context, str, DataCache);
    }

    public static String loadCache(Context context) {
        return new DataCache().loadGlobal(context, DataCache);
    }

    /* access modifiers changed from: package-private */
    /* renamed from: com.androidx.lv.base.utils.AccountCacheUtils$DataCache */
    public static class DataCache<T> {
        DataCache() {
        }

        public void save(Context context, String str, String str2) {
            save(context, str, str2, "");
        }

        public void saveGlobal(Context context, String str, String str2) {
            save(context, str, str2, AccountCacheUtils.DataCache);
        }

        private void save(Context context, String str, String str2, String str3) {
            File file;
            if (context != null) {
                if (!str3.isEmpty()) {
                    File file2 = new File(AccountCacheUtils.savePath, str3);
                    if (!file2.exists() || !file2.isDirectory()) {
                        file2.mkdir();
                    }
                    file = new File(file2, str2);
                } else {
                    file = new File(AccountCacheUtils.savePath, str2);
                }
                if (file.exists()) {
                    file.delete();
                }
                Log.d("everb", file.getAbsolutePath());
                try {
                    ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file));
                    objectOutputStream.writeObject(str);
                    objectOutputStream.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        public String load(Context context, String str) {
            return load(context, str, "");
        }

        public String loadGlobal(Context context, String str) {
            return load(context, str, AccountCacheUtils.DataCache);
        }

        /* JADX WARNING: Removed duplicated region for block: B:22:0x0073  */
        /* JADX WARNING: Removed duplicated region for block: B:23:0x0079  */
        private String load(Context context, String str, String str2) {
            File file;
            String str3;
            Exception e;
            if (!str2.isEmpty()) {
                File file2 = new File(AccountCacheUtils.savePath, str2);
                if (!file2.exists() || !file2.isDirectory()) {
                    file2.mkdir();
                }
                file = new File(file2, str);
            } else {
                file = new File(AccountCacheUtils.savePath, str);
            }
            Log.d("everb", "file " + file.getAbsolutePath());
            if (file.exists()) {
                try {
                    Log.d("everb", "write object");
                    ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(file));
                    str3 = (String) objectInputStream.readObject();
                    try {
                        objectInputStream.close();
                    } catch (Exception e2) {
                        e = e2;
                    }
                } catch (Exception e3) {
                    e = e3;
                    str3 = "";
                    Log.d("everb", e.toString());
                    if (str3 == null) {
                    }
                }
            } else {
                str3 = "";
            }
            if (str3 == null) {
                return str3;
            }
            Log.d("everb", "data == null");
            return "";
        }
    }
}
